package models

import (
	"github.com/beego/beego/v2/adapter/orm"
	beego "github.com/beego/beego/v2/server/web"
)

func Init() {
	dbhost,_ := beego.AppConfig.String("dbhost")
	dbport,_ := beego.AppConfig.String("dbport")
	dbuser,_ := beego.AppConfig.String("dbuser")
	dbpassword,_ := beego.AppConfig.String("dbpassword")
	dbname,_ := beego.AppConfig.String("dbname")
	if dbport == "" {
		dbport = "3306"
	}

	dsn := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?charset=utf8&loc=Asia%2FShanghai"
	orm.RegisterDataBase("default", "mysql", dsn)
	orm.RegisterModel(new(User))
}

//返回带前缀的表名
func TableName(str string) string {
	dbprefix,_ :=beego.AppConfig.String("dbprefix")

	return dbprefix + str
}

